//! 基础消息

use crate::bean::message::message_type::MessageType;

#[derive(Debug, Clone, Default)]
pub struct BaseMessage {
    msg_type: MessageType, // 消息类型
    from_address: String,  // 发送地址
    signature: String,     // 签名
    pub_key: String,       // 公钥
    timestamp: i64,        // 时间戳
}

impl BaseMessage {
    pub fn new(
        msg_type: MessageType,
        from_address: &str,
        signature: &str,
        pub_key: &str,
        timestamp: i64,
    ) -> Self {
        Self {
            msg_type,
            from_address: from_address.to_string(),
            signature: signature.to_string(),
            pub_key: pub_key.to_string(),
            timestamp,
        }
    }

    pub fn msg_type(&self) -> MessageType {
        self.msg_type
    }

    pub fn from_address(&self) -> &str {
        &self.from_address
    }

    pub fn signature(&self) -> &str {
        &self.signature
    }

    pub fn pub_key(&self) -> &str {
        &self.pub_key
    }

    pub fn timestamp(&self) -> i64 {
        self.timestamp
    }

    pub fn set_msg_type(&mut self, msg_type: MessageType) {
        self.msg_type = msg_type;
    }

    pub fn set_from_address(&mut self, from_address: &str) {
        self.from_address = from_address.to_string();
    }

    pub fn set_signature(&mut self, signature: &str) {
        self.signature = signature.to_string();
    }

    pub fn set_pub_key(&mut self, pub_key: &str) {
        self.pub_key = pub_key.to_string();
    }

    pub fn set_timestamp(&mut self, timestamp: i64) {
        self.timestamp = timestamp;
    }
}
